<template>
    <div class="components-container">
        <!-- 派车登记 -->
        <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="maxWidth">
            <h3>{{title}}</h3>
            <div style=" height:500px; margin:10px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">业务编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.bussNO" placeholder="请输入业务编号" @keyup.enter.native="getSendCarByNo" :readonly="txtBussNoReadonly"></el-input>
                        </div>
                        <el-button type="primary" @click="getSendCarByNo" v-if="btnBussNoShow">获取</el-button>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.deadName" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系人</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.linkMan" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.linkTel" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="this.isshowyw">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者性别</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.DEADSEXDESC" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者年龄</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.DEADAGE" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者关系</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.RELATION" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">  
                        <label class="layui-form-label">接尸时间</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.JSDATEDESC" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">接尸地点</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.JSADDRESS" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.deadRemark" type="textarea" class="longertext" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <el-button type="primary" @click="operateCdh('新增')" :disabled="showAdd">添加派车</el-button>
                    </div>
                </div>
                <div class="div-card">
                    <el-card v-for="item in deaddata.cdhList" :key="item.CDHID">
                        <div class="layui-inline">
                            <label>出车类型:{{ item.CDHCODNAME}}</label>
                            <label>车牌号:{{item.CARLIC}}</label>
                            <label>驾驶员:{{item.STANAME}}</label>
                        </div>
                        <div class="layui-inline" v-if="!isShow">
                            <label>出车地址:{{item.CDHADDRESS}}</label>
                        </div>
                        <div class="layui-inline" v-if="isShow">
                            <label>出车地址:{{item.CDHADDID}}</label>
                        </div>
                        <div class="layui-inline">
                            <label>出车时间:{{item.CDHACTUALDATE}}&nbsp;{{item.CDHACTUALTIME}}</label>
                            <label>返回时间:{{item.CDHENDDATE}}&nbsp;{{item.CDHENDTIME}}</label>
                            <label>里程:{{item.CDHMILEAGE}}</label>
                        </div>
                        <div class="layui-inline">
                            <label>接运员:{{item.CarryName}}</label>
                            <label v-if="!isShow">统计:{{item.CensName}}</label>
                            <label v-if="IsShowOvertime">加班时长:{{item.CDHOVERTIMEHOURS}}</label>
                            <label>备注:{{item.CDHREMARKS}}</label>
                        </div>
                        <div class="layui-inline" v-if="IsChargeAndSpecial">
                            <label>是否已打印:{{item.CDHISPRINT}}</label>
                        </div>
                        <div class="layui-form-item">
                            <el-button type="primary" @click="operateCdh('修改',item.CDHID)">修改</el-button>
                            <el-button type="primary" @click="deleteCarInfo(item.CDHID)">删除</el-button>
                            <el-button type="primary" @click="operateCdh('打印派车单',item.CDHID)">打印派车单</el-button>
                        </div>
                    </el-card>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" @click="cancel">确定</el-button>
            </div>
        </sweet-modal>
        <!-- 详情 -->
        <sweet-modal ref="info" class="dialog" :sweetModalMaxWidth="maxWidth">
            <h3>{{title}}</h3>
            <div style=" height:500px; margin:10px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">业务编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.bussNO" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者姓名</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.deadName" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系人</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.linkMan" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.linkTel" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="this.isshowyw">
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者性别</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.DEADSEXDESC" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者年龄</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.DEADAGE" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">逝者关系</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.RELATION" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">  
                        <label class="layui-form-label">接尸时间</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.JSDATEDESC" readonly></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">接尸地点</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.JSADDRESS" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <el-input v-model="deaddata.deadRemark" class="longertext" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="div-card">
                    <el-card v-for="item in deaddata.cdhList" :key="item.CDHID">
                        <div class="layui-inline">
                            <label>出车类型:{{ item.CDHCODNAME}}</label>
                            <label>车牌号:{{item.CARLIC}}</label>
                            <label>驾驶员:{{item.STANAME}}</label>
                        </div>
                        <div class="layui-inline" v-if="!isShow">
                            <label>出车地址:{{item.CDHADDRESS}}</label>
                        </div>
                        <div class="layui-inline" v-if="isShow">
                            <label>出车地址:{{item.CDHADDID}}</label>
                        </div>
                        <div class="layui-inline">
                            <label>出车时间:{{item.CDHACTUALDATE}}&nbsp;{{item.CDHACTUALTIME}}</label>
                            <label>返回时间:{{item.CDHENDDATE}}&nbsp;{{item.CDHENDTIME}}</label>
                            <label>里程:{{item.CDHMILEAGE}}</label>
                        </div>
                        <div class="layui-inline">
                            <label>接运员:{{item.CarryName}}</label>
                            <label v-if="!isShow">统计:{{item.CensName}}</label>
                            <label v-if="IsShowOvertime">加班时长:{{item.CDHOVERTIMEHOURS}}</label>
                            <label>备注:{{item.CDHREMARKS}}</label>
                        </div>
                    </el-card>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="infoClose">确定</el-button>
            </div>
        </sweet-modal>
        <!-- 新增 || 修改-->
        <sweet-modal ref="dialog1" class="dialog" :sweetModalMaxWidth="800">
            <h3>{{cdhtitle}}</h3>
            <div style=" height:300px; width:700px; margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">出车类型</label>
                        <div class="layui-input-inline">
                            <el-select v-model="cdhdata.CDHCODNAME" placeholder="出车类型">
                                <el-option v-for="item in cdhTypes" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">派车车辆</label>
                        <div class="layui-input-inline">
                            <el-cascader :options="carLics" v-model="cdhextend.cardata">
                            </el-cascader>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">驾驶员</label>
                        <div class="layui-input-inline">
                            <el-select v-model="cdhdata.CDHDRIVER" placeholder="司机">
                                <el-option v-for="item in drivers" :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="!nolimit">
                        <label class="layui-form-label">接运员</label>
                        <div class="layui-input-inline">
                            <el-select v-model="cdhdata.List_Carry" placeholder="接运员" multiple :multiple-limit=2>
                                <el-option v-for="item in carriers" :key="item.value" :label="item.label" :value="item.value"></el-option>
                            </el-select>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="nolimit">
                        <label class="layui-form-label">接运员</label>
                        <div class="layui-input-inline">
                            <el-select v-model="cdhdata.List_Carry" placeholder="接运员" multiple>
                                <el-option v-for="item in carriers" :key="item.value" :label="item.label" :value="item.value"></el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline" v-if="!isShow">
                        <label class="layui-form-label">出车地址</label>
                        <div class="layui-input-inline">
                            <el-input v-model="cdhdata.CDHADDRESS" placeholder="出车地址" class="longtext"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="isShow">
                        <label class="layui-form-label">出车地址</label>
                        <div class="layui-input-inline">
                            <el-select v-model="cdhdata.CDHADDRESS" @change="selectAddr" placeholder="请选择常用接尸地址">
                                <el-option :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue" v-for="item in commonAddr"></el-option>
                            </el-select>
                        </div>
                        <div class="layui-input-inline backcolor">
                            <el-input v-model="cdhdata.CDHADDID" style="width:280px"></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">出车时间</label>
                        <div class="layui-input-inline chooseTime"> 
                            <!-- CDHENDDATE  CDHENDTIME   CDHACTUALDATE  CDHACTUALTIME -->
                            <!-- <el-date-picker v-date v-model="cdhActualDateTime" type="datetime" placeholder="选择时间"></el-date-picker> -->
                            <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="cdhActualDateTime"></el-date-picker>
                            <el-time-picker style="width:75px;float:left" clear-icon="null" v-date v-model="cdhActualDateTime" format="HH:mm" @change="changetj($event)"></el-time-picker>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">返回时间</label>
                        <div class="layui-input-inline chooseTime">
                            <!-- <el-date-picker v-date v-model="cdhEndDateTime" type="datetime" placeholder="选择时间"> </el-date-picker> -->
                            <el-date-picker style="width:115px;float:left;" clear-icon="null" type="date" v-date v-model="cdhEndDateTime"></el-date-picker>
                            <el-time-picker style="width:75px;float:left" clear-icon="null" v-date v-model="cdhEndDateTime" format="HH:mm"></el-time-picker>
                        </div>
                    </div>
                    <div v-if="isShow" class="layui-inline">
                        <label class="layui-form-label">超时</label>
                        <div class="layui-input-inline">
                            <el-input v-model="cdhdata.CDHOUTTIM" placeholder="超出时间"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="isShow">
                        <label class="layui-form-label">出车里程<span class="text-danger">*</span></label>
                        <div class="layui-input-inline">
                            <el-input v-model="cdhdata.CDHMILEAGE" placeholder="里程"></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="!isShow">
                    <div class="layui-inline">
                        <label class="layui-form-label">出车里程<span class="text-danger">*</span></label>
                        <div class="layui-input-inline">
                            <el-input v-model="cdhdata.CDHMILEAGE" placeholder="里程"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">统计</label>
                        <div class="layui-input-inline">
                            <el-select v-model="cdhdata.List_Census" placeholder="统计" multiple>
                                <el-option v-for="item in censusTypes" :key="item.value" :label="item.label" :value="item.value"></el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="isshowjiaban">
                    <div class="layui-inline">
                        <label class="layui-form-label">是否加班</label>
                        <div class="layui-input-inline">
                            <el-select v-model="cdhdata.CDHISWORKOVERTIME" filterable> 
                                <el-option label="加班" value="1"></el-option>
                                <el-option label="不加班" value="0"></el-option>
                            </el-select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">是否值班</label>
                        <div class="layui-input-inline">
                            <el-select v-model="cdhdata.CDHISCHARGE" filterable>
                                <el-option label="值班" value="1"></el-option>
                                <el-option label="非值班" value="0"></el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <el-input type="textarea" :class=" !IsShowOvertime? 'longtext': ''" v-model="cdhdata.CDHREMARKS"></el-input>
                        </div>
                    </div>
                    <div class="layui-inline" v-if="IsShowOvertime">
                        <label class="layui-form-label">加班时长</label>
                        <div class="layui-input-inline">
                            <el-input v-model="cdhdata.CDHOVERTIMEHOURS"></el-input>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="cancel1">取消</el-button>
                <el-button type="primary" @click="submit" :loading="this.$store.state.isloading">提交</el-button>
            </div>
        </sweet-modal>
        <!-- <printPdf ref="prints"></printPdf> -->
        <sweet-modal ref="dialogPrint" class="dialog" :sweetModalMaxWidth="pageWidth">
            <h3>{{cdhtitle}}</h3>
            <iframe :src="printUrl" style="width:1100px; height:500px;margin-top:20px;"></iframe>
        </sweet-modal>
    </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
<script>
    import sweetModal from "@/components/sweetModal";
    import apiBase from "@/api/apiBase.js";
    import {
        formatDate,
        timeStringToDate
    } from "@/utils/date.js";
    import {
        manage
    } from "@/mixins/managePage.js";
    import {
        PRINT
    } from "@/components/Pdf/PDF.js"
    const ADD = "新增";
    const CARSEND = "派车";
    const MODIFY = "修改";
    const DELETE = "删除";
    const INFO = "详情";
    const PRINTCARSEND = "打印派车单"
    export default {
        name: "carSendMain",
        mixins: [manage],
        data() {
            return {
                maxWidth: 1100,
                pageWidth: 1200,
                maxHeight: 500,
                printUrl: null,
                commonAddr: [],
                cdhdata: {
                    CDHCODNAME: null,
                    CARCODNAME: null,
                    CDHCARID: null,
                    CDHDRIVER: null,
                    CDHCARRY: null,
                    CDHADDRESS: null,
                    CDHADDID: null,
                    CDHACTUALDATE: null,
                    CDHACTUALTIME: null,
                    CDHENDDATE: null,
                    CDHENDTIME: null,
                    CDHMILEAGE: null,
                    CDHREMARKS: null,
                    CDHOVERTIMEHOURS: null,
                    CDHSTATUS: null,
                    CDHOUTTIM: null,
                    //CDHCENSUS:null,
                    List_Census: [],
                    List_Carry: []
                },
                cdhextend: {
                    cardata: []
                },
                IsShowOvertime: null ,
                cdhActualDateTime: null,
                // cdhGobackTime: null,
                cdhEndDateTime: null,
                deaddata: {
                    bussID: null,
                    bussNO: null,
                    deadName: null,
                    linkMan: null,
                    linkTel: null,
                    deadRemark: null,
                    pcrAddress: null,
                    pcrDate: null,
                    pcrCarType: null,
                    cdhList: []
                },
                type: null,
                carLics: [],
                carriers: [],
                cdhstatus: [],
                drivers: [],
                censusTypes: [],
                bussStatus: [],
                cdhTypes: [],
                title: null,
                cdhtitle: null,
                isShow: null,
                IsChargeAndSpecial:null,
                isshowjiaban: null,
                isshowyw: null,
                datetimes: null,
                adress: null,
                IsTurnoutDefaultTakecorpse: null,
                nolimit:null,  //上虞  不限制接运人数
            };
        },
        methods: {
            open(order, id, ...items) {
                this.order = order;
                this.datetimes = items[0];
                this.adress = items[1];
                switch (this.order) {
                    case CARSEND:
                        this.title = "派车登记";
                        this.deaddata.bussNO = id;
                        this.getSendCarByNo();
                        this.$refs.dialog.open();
                        break;
                    case INFO:
                        this.title = "派车详情";
                        this.deaddata.bussNO = id;
                        this.getSendCarByNo();
                        this.$refs.info.open();
                        break;
                    default:
                }
            },
            operateCdh(order, cdhid) {
                this.cdhorder = order;
                if (cdhid) this.cdhdata.CDHID = cdhid;
                switch (this.cdhorder) {
                    case ADD:
                        this.cdhtitle = "派车新增";
                        this.CdhdataRepeat();
                        this.initSelect();
                        this.$refs.dialog1.open();
                        break;
                    case MODIFY:
                        this.cdhtitle = "派车修改";
                        this.initSelect();
                        this.dataDetail();
                        this.$refs.dialog1.open();
                        break;
                    case PRINTCARSEND:
                        this.cdhtitle = "派车单打印";
                        //this.cdhorder, null, this.cdhdata.CDHID
                        this.getPRINTSEND();
                        this.$refs.dialogPrint.open();
                        break;
                    default:
                }
            },
            selectAddr(){
                this.cdhdata.CDHADDID = this.cdhdata.CDHADDRESS;
            },
            //提交
            submit() {
                switch (this.cdhorder) {
                    case ADD:
                    case MODIFY:
                        this.EditSendCar();
                        break;
                    case DELETE:
                        break;
                    default:
                }
            },
            //初始化下拉框
            initSelect() {
                this.getSendCdhTypes();
                this.getSendCdhStatus();
                this.getCar();
                this.getDrivers();
                this.getBussStatus();
                this.getCarriers();
                this.getCensusTypes();
                this.getCommonAddr();
            },
            //根据预约号和业务编号获取派车信息
            getSendCarByNo() {
                let data = {
                    BussNo: this.deaddata.bussNO
                };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Sendcar.GetSendCarByNo,
                    res => {

                        let cdhsList = res.data.content;
                     
                        this.deaddata.bussID = cdhsList.BUSSID;
                        this.deaddata.deadName = cdhsList.DEADNAME;
                        this.deaddata.linkMan = cdhsList.LINKMAN;
                        this.deaddata.linkTel = cdhsList.LINKPHONE;
                        this.deaddata.deadRemark = cdhsList.REMARK;
                        this.deaddata.pcrAddress = cdhsList.Pcr.PCRADDRESS;
                        this.deaddata.pcrDate = cdhsList.Pcr.PCRDATE;
                        this.deaddata.pcrCarType = cdhsList.Pcr.PCRCARTYPE;
                        this.deaddata.cdhList = cdhsList.Cdhs;

                        // 义务新增字段
                        this.deaddata.DEADSEXDESC = cdhsList.DEADSEXDESC;
                        this.deaddata.DEADAGE = cdhsList.DEADAGE;
                        this.deaddata.JSDATEDESC = cdhsList.JSDATEDESC;
                        this.deaddata.JSADDRESS = cdhsList.JSADDRESS;
                        this.deaddata.RELATION = cdhsList.RELATION;


                        //  this.deaddata.CDHCENSUS = cdhsList.CDHCENSUS;
                    }
                );
            },
            //添加修改派车记录 
            EditSendCar() {
                var data = JSON.parse(JSON.stringify(this.cdhdata));
                data.CDHACTUALDATE = formatDate(this.cdhActualDateTime, "yyyyMMdd");
                data.CDHACTUALTIME = formatDate(this.cdhActualDateTime, "hhmmss");
                data.CDHENDDATE = formatDate(this.cdhEndDateTime, 'yyyyMMdd');
                data.CDHENDTIME = formatDate(this.cdhEndDateTime, 'hhmmss');
                data.BUSSID = this.deaddata.bussID;
                data.CDHCARID = this.cdhextend.cardata[this.cdhextend.cardata.length - 1];
                  data.CensName=null;
                  data.CDHCENSUS=null;
                if (this.cdhorder == ADD) {
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Sendcar.Create,
                        res => {
                            this.getSendCarByNo();
                            this.$message.success("派车成功");
                            this.$refs.dialog1.close();
                            this.refreshData();
                        },
                        res => {
                            this.$message.error(res.data.msg);
                        }
                    );
                } else if (this.cdhorder == MODIFY) {
                   
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Sendcar.Modify,
                        res => {
                            console.log(this.$route.path);
                            if(this.$route.path === '/carSend'){
                                this.getSendCarByNo();
                            }
                            this.$message.success("修改成功");
                            this.$refs.dialog1.close();
                            this.refreshData();
                        },
                        res => {
                            this.$message.error(res.data.msg);
                        }
                    );
                }
            },
            //出车时间改变是统计也改变
            changetj(val){
                let gethours = val.getHours();
                if(gethours){
                    if(gethours >= 19 || gethours <= 7){
                        if(this.cdhdata.List_Census.indexOf('早班') == -1){
                            this.cdhdata.List_Census.push('早班');
                        }
                    }else{
                        if(this.cdhdata.List_Census.indexOf('早班') !== -1){
                            for(var i=0; i<this.cdhdata.List_Census.length; i++){
                                if(this.cdhdata.List_Census[i] == '早班'){
                                    this.cdhdata.List_Census.splice(i,1);
                                }
                            }
                        }
                    }
                }
            },
            //详情 --派车
            dataDetail() {
                var data = {
                    CDHID: this.cdhdata.CDHID
                };
                apiBase.DoService(data, apiBase.getApiAdress().Sendcar.Detail, res => {
                    this.cdhdata = res.data.content;
                    this.cdhActualDateTime = timeStringToDate(this.cdhdata.CDHACTUALTIME, this.cdhdata.CDHACTUALDATE);
                    // let gethours = this.cdhActualDateTime.getHours();
                    // if(this.cdhdata.List_Census.indexOf('早班') == -1){
                    //     if(gethours){
                    //         if(gethours >= 19 || gethours <= 7){
                    //             this.cdhdata.List_Census.push('早班');
                    //         }
                    //     }
                    // };
                    this.cdhEndDateTime = timeStringToDate(this.cdhdata.CDHENDTIME, this.cdhdata.CDHENDDATE);
                    
                    if (!this.cdhdata.List_Census) this.cdhdata.List_Census;

              
                    this.cdhdata.CDHACTUALTIME = timeStringToDate(this.cdhdata.CDHACTUALTIME);
                    this.cdhdata.CDHENDTIME = timeStringToDate(this.cdhdata.CDHENDTIME);
                    this.cdhextend.cardata = [
                        this.cdhdata.CARCODNAME,
                        this.cdhdata.CDHCARID
                    ];
                    let findarry = this.carLics.filter(item => {
                        return item.value === this.cdhdata.CARCODNAME;
                    });
                    if (findarry.length > 0) {
                        let seachCarType = findarry[0];
                        if (!seachCarType.children.some(item => {
                                return item.value === this.cdhdata.CDHCARID;
                            }))
                            seachCarType.children.push({
                                label: this.cdhdata.CARLIC,
                                value: this.cdhdata.CDHCARID
                            });
                    }
                    if(this.cdhdata.CDHDRIVER != ""){
                        if (!this.drivers.some(item => {
                            return item.value === this.cdhdata.CDHDRIVER;
                        }))
                        this.drivers.push({
                            label: this.cdhdata.STANAME,
                            value: this.cdhdata.CDHDRIVER
                        });
                    }
                });
            },
            //删除派车记录
            deleteCarInfo(chdid) {
                this.$confirm("此操作将永久删除该派车信息, 是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(callback => {
                    var data = {
                        CDHID: chdid
                    };
                    apiBase.DoService(data, apiBase.getApiAdress().Sendcar.Delete, res => {
                        this.getSendCarByNo();
                    });
                });
            },
            //死亡人员数据重置
            DeaddataRepeat() {
                Object.assign(this.$data.deaddata, this.$options.data().deaddata);
            },
            //派车数据重置
            CdhdataRepeat() {
                Object.assign(this.$data.cdhdata, this.$options.data().cdhdata);
                Object.assign(this.$data.cdhextend, this.$options.data().cdhextend);
                if (this.cdhorder === ADD) {
                    this.cdhdata.CDHADDRESS = this.deaddata.pcrAddress;
                    this.cdhdata.CDHACTUALDATE = this.deaddata.pcrDate;
                    this.cdhextend.cardata = [this.deaddata.pcrCarType, ""];
                }
                if(this.IsTurnoutDefaultTakecorpse){
                    this.cdhActualDateTime = new Date(this.datetimes);
                    this.cdhdata.CDHADDRESS = this.adress;
                }else{
                    this.cdhActualDateTime = new Date();
                }
                
                this.cdhEndDateTime = null;
            },
            //获取派车类别
            getSendCdhTypes() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Code.GetSendCdhType,
                    res => {
                        let cdhTypeData = res.data.content,
                            legendsCdhData = cdhTypeData.map(item => ({
                                label: item.CodeName,
                                value: item.CodeValue
                            }));
                        this.cdhTypes = legendsCdhData;
                    }
                );
            },
            //获取常用地址
            getCommonAddr() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Code.GetCommonAddress,
                    res => {
                        this.commonAddr = res.data.content;
                    }
                );
            },
            //获取派车状态
            getSendCdhStatus() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Sendcar.GetCdhStatus,
                    res => {
                        this.cdhstatus = res.data.content;
                    }
                );
            },
            //获取车辆信息
            getCar() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Car.QueryCarByType,
                    res => {
                        let cardata = res.data.content;
                        let legendsCarData = cardata.map(item => ({
                            label: item.CodeName,
                            value: item.CodeValue,
                            children: item.list_Cars.map(caritem => ({
                                label: caritem.CARLIC,
                                value: caritem.CARID
                            }))
                        }));
                        this.carLics = legendsCarData;
                    }
                );
            },
            //获取司机
            getDrivers() {
                let data = {};
                apiBase.DoService(data, apiBase.getApiAdress().Staff.QueryDriver, res => {
                    let driverData = res.data.content,
                        legendsDrivers = driverData.map(item => ({
                            label: item.STANAME,
                            value: item.STAID
                        }));
                    this.drivers = legendsDrivers;
                });
            },
            //获取业务状态
            getBussStatus() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Sendcar.GetBusstype,
                    res => {
                        this.bussStatus = res.data.content;
                    }
                );
            },
            //获取接运员
            getCarriers() {
                let data = {};
                apiBase.DoService(data, apiBase.getApiAdress().Staff.QueryCarry, res => {
                    let carryData = res.data.content,
                        legendsCarriers = carryData.map(item => ({
                            label: item.STANAME,
                            value: item.STAID
                        }));
                    this.carriers = legendsCarriers;
                });
            },
            //获取派车统计编码
            getCensusTypes() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Code.GetCensustype,
                    res => {
                        let censusTypeData = res.data.content,
                            legendsCensusData = censusTypeData.map(item => ({
                                label: item.CodeName,
                                value: item.CodeValue
                            }));
                        this.censusTypes = legendsCensusData;
                    }
                );
            },
            //获取接尸通知单URL
            getPRINTSEND() {
                let data = {
                    PRPID: null,
                    CDHID: this.cdhdata.CDHID
                };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Pdf.PrintCdh,
                    res => {
                        this.printUrl = res.data.content.PDFNAME;
                        this.$refs.dialogPrint.open();
                    });
            },
            //关闭派车信息弹窗
            cancel1() {
                this.$refs.dialog1.close();
            },
            //刷新
            refreshData() {
                this.$emit("refreshData");
            },
        },
        components: {
            sweetModal,
        },
        computed: {
            showAdd() {
                return this.deaddata.bussID === null;
            },
            btnBussNoShow() {
                return this.order === ADD;
            },
            txtBussNoReadonly() {
                return this.order === MODIFY;
            }
        },
        created() {
            apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetIsMultiSelectCDF,
                res => {
                    this.nolimit = res.data.content  //上虞个性化  不限制接运人数
                });
            apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetIsShowOutOfTime,
                res => {
                    this.isShow = res.data.content  //余姚个性化
                });
            apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetIsChargeAndSpecial,
                res => {
                    this.IsChargeAndSpecial = res.data.content
                });
            apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetSendCar,
                res => {
                    this.isshowjiaban = res.data.content
                });
            apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetIsShowCreBy_YW,
                res => {
                    this.isshowyw = res.data.content
                });
            apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetIsShowOvertimeHours,
                res => {
                    this.IsShowOvertime = res.data.content //控制是否显示加班时长
                });
            apiBase.DoService(
                {},
                apiBase.getApiAdress().Param.GetIsTurnoutDefaultTakecorpse,
                res => {
                    this.IsTurnoutDefaultTakecorpse = res.data.content //控制是否显示加班时长
                });
        }
    };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    @import "src/styles/common.scss";
    .el-form-item {
        margin-bottom: 0px;
    }
    .div-card {
        max-height: 300px;
        overflow: auto;
    }
    .div-card label {
        min-width: 100px;
        font-weight: 400;
        padding-left: 20px;
    }
    .btnCenter {
        text-align: center;
    }
    .longtext {
        width: 480px;
    }
    .longertext {
        width: 770px;
    }
</style>

